﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MushroomPicker
{
	public partial class ScorePanel : UserControl
	{
        public static ScorePanel Current { get; private set; }
		public ScorePanel()
		{
			// Required to initialize variables
			InitializeComponent();
            Current = this;
            ANI_Time.Completed += new EventHandler(ANI_Time_Completed);
		}

        void ANI_Time_Completed(object sender, EventArgs e)
        {
            if (TimeOver != null)
                TimeOver();
        }
        public double ScoreValue
        {
            get { return (double)GetValue(ScoreValueProperty); }
            set { SetValue(ScoreValueProperty, value); }
        }
        public static readonly DependencyProperty ScoreValueProperty =
            DependencyProperty.Register("ScoreValue", typeof(double), typeof(ScorePanel), new PropertyMetadata(new PropertyChangedCallback(OnScoreValueChanged)));
        static void OnScoreValueChanged(DependencyObject dobj, DependencyPropertyChangedEventArgs ea)
        {
            var my = dobj as ScorePanel;
            if (my != null)
            {
                var s = (double)ea.NewValue;
                my.textScoreValue1.Text =((int)s).ToString();
                my.textScoreValue2.Text = ((int)s).ToString();
            }
        }
        public void StartTime(int level)
        {
            endFrame.KeyTime = KeyTime.FromTimeSpan( TimeSpan.FromSeconds(9d + (double)level));
            ANI_Time.Begin();
        }
        public void StopTime()
        {
            ANI_Time.Stop();
        }
        public Action TimeOver { get; set; }
	}
}